﻿using ETestIT.Core;

namespace ETestIT.UI.AppControls
{
    using System;
    
    using Core.Infrastructure;
    using SharpArch.Core.PersistenceSupport;
    public partial class ClientAddEdit : UserControlBase<Client>
    {
        IRepository<Client> clientRepository;

        protected void Page_Load(object sender, EventArgs e)
        {
            clientRepository = IoC.Resolve<IRepository<Client>>();
            if(!IsPostBack)
            {
                DindDdlToEnum<ClientType>(ddlTypeOfClients);
            }
        }

        public override void ShowModel(Client entity)
        {
            base.ShowModel(entity);

            if (entity.Id == 0)
            {
                tbName.Text =
                    tbContactInformation.Text = string.Empty;
                return;
            }

            tbName.Text = entity.Name;
            tbContactInformation.Text = entity.ContactInformation;
            ddlTypeOfClients.SelectedValue = entity.TypeOfClient.ToString() ;
            
        }
        public override void UpdateModel(Client entity)
        {
            base.UpdateModel(entity);
            entity.Name = tbName.Text;
            entity.ContactInformation = tbContactInformation.Text;
            GetEnumValueFromListControl<ClientType>(ddlTypeOfClients);

            
           
        }
    }
}